package com.krdz.provider;

import org.apache.ibatis.jdbc.SQL;

import com.krdz.bean.UserBean;

/**
 * 用户管理sql
 * @author dinghao
 *
 * @date  2018年11月15日
 */
public class UserProvider {
	
	//查询用户基本信息
	public String findUserInfoSql(){
		
		return new SQL(){
			{
				SELECT("*");
				FROM("user_info as user");	
			}
		}.toString();
	}
	//根据ID查询用户信息
	public String findUserByIdfoSql(Integer id){
		
		return new SQL(){
			{
				SELECT("*");
				FROM("user_info as user");	
				WHERE("user.id=#{id}");
			}
		}.toString();
	}
	//查询用户总记录数
	public String findUserCountSql(){
		
		return new SQL(){
			{
				SELECT("count(*)");
				FROM("user_info as user");	
			}
		}.toString();
	}
	//添加用户信息
	public String insertUserSql(){
		
		return new SQL(){
			{
				INSERT_INTO("user_info");
				VALUES("user_code","#{userCode}");
				VALUES("user_name","#{userName}");
				VALUES("password","#{passWord}");
				VALUES("rolename","#{roleName}");
				VALUES("USER_STATUS","#{userStatus}");				
				VALUES("remark","#{remark}");
			}
		}.toString();
	}
	//修改用户信息
	public String updateUserSql(final UserBean user){
		return new SQL(){
			{				
				UPDATE("user_info");
				SET("user_name=#{userName}");
				SET("password=#{passWord}");
				SET("rolename=#{roleName}");
				SET("USER_STATUS=#{userStatus}");
				SET("remark=#{remark}");
				if(user!=null){
					if(user.getUserCode()!=null&&user.getUserCode()!=""){
						WHERE("user_code=#{userCode}");
					}
				}
				
			}
		}.toString();
	}
	//删除用户信息
	public String deleteUserSql(final Integer id){
		return new SQL(){
			{				
				DELETE_FROM("user_info");
				WHERE("id=#{id}");				
			}
		}.toString();
	}
}
